<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 动态 model
 *
 */
class Activemodel extends CI_Model {

	function __construct()
    {
        parent::__construct();
    }
    
    /**
     * 添加动态
     *
     */
    function insert_active($data=array())
    {
    	if(empty($data)){
			return FALSE;
		}
    	$this->dblib->create_id();
    	return $this->db->insert('active', $data);
    }
    
    /**
     * 动态数目
     *
     */
    function get_active_count($uid='')
    {
    	$this->db->select('count(*) as count')
    			 ->from('active')
    			 ->where(array('uid' => $uid));
    	$query = $this->db->get();
    	$row = $query->row_array();
    	return $row['count'];
    }
    
    /**
     * 根据添加时间依次获取动态
     *
     */
    function get_actives_by_createtime($uid=array())
    {
    	$this->dblib->set_query_limit();//设置分页
    	$this->db->order_by('createtime', 'desc');//降序排序
    	if(count($uid) > 0){
    		$this->db->where_in('uid', $uid);
    	}
    	$query = $this->db->get('active');
    	return $query->result_array();
    }
    
    /**
     * 检测给定的动态是否有效
     *
     * @param unknown_type $id
     */
    function check_app($id='', $uid='', $belong_user=1)
    {
    	$where = array('id' => $id);
    	if($uid && $belong_user){
    		$where['uid'] = $uid;
    	}elseif($uid && !$belong_user){
    		$where['uid <>'] = $uid;
    	}
    	
    	$this->db->select('count(*) as count');
		$this->db->where($where, FALSE);
		$query = $this->db->get('active');
		$row = $query->row_array();
		return $row['count'] > 0;
    }
    
}


/* End of file activemodel.php */
/* Location: ./application/models/activemodel.php */